// LengthUnit1.cpp: implementation of the LengthUnit class.
//
//////////////////////////////////////////////////////////////////////

#include "LengthUnit.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

#define INCH_TO_BASE_UNIT 1
#define FEET_TO_BASE_UNIT 12*INCH_TO_BASE_UNIT
#define YARD_TO_BASE_UNIT (3*FEET_TO_BASE_UNIT)
#define MILE_TO_BASE_UNIT (1760*YARD_TO_BASE_UNIT)

#define MILE_NAME "MILE"
#define YARD_NAME "YARD"
#define FEET_NAME "FEET"
#define INCH_NAME "INCH"

static Unit::UnitVector unitSeq;

LengthUnit::LengthUnit(const Amount& factor, const string& str)
:Unit(factor, str)
{
	setUnitSeq();
}

const LengthUnit& LengthUnit::getMile()
{
	static const LengthUnit mile(MILE_TO_BASE_UNIT, MILE_NAME);
	return mile;
}

const LengthUnit& LengthUnit::getYard()
{
	static const LengthUnit yard(YARD_TO_BASE_UNIT, YARD_NAME);
	return yard;
}

const LengthUnit& LengthUnit::getFeet()
{
	static const LengthUnit feet(FEET_TO_BASE_UNIT, FEET_NAME);
	return feet;
}

const LengthUnit& LengthUnit::getInch()
{
	static const LengthUnit inch(INCH_TO_BASE_UNIT, INCH_NAME);
	return inch;
}

const Unit* LengthUnit::getBaseUnit()
{
	return &(getInch());
}

void LengthUnit::setUnitSeq()
{
	insert(&FEET, &unitSeq);
	insert(&YARD, &unitSeq);
	insert(&INCH, &unitSeq);
	insert(&MILE, &unitSeq);
}

Unit::UnitVector& LengthUnit::getUnitSeq()
{
	return unitSeq;
}
